<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录 - 宠物管理系统</title>
    <script src="static/jquery-3.6.0.min.js"></script>
    <style>
        /* General CSS styles */
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-image: url('../static/images/1.jpg');
            /* Replace with your image path */
            background-size: cover;
            background-position: center;
            background-color: #f3e9e9;
            /* 浅粉色背景 */
        }

        header {
            background-color: #333;
            color: #fff;
            padding: 20px 0;
            text-align: center;
            /* 居中对齐标题内容 */
        }


        main {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 80vh;
        }

        .login-container {
            background-color: rgba(255, 255, 255, 0.1);
            /* 调整更亮的透明度 */
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
            max-width: 90%;
            text-align: center;
            margin-top: 20px;
            /* Added margin-top for spacing */
        }

        .login-container h1 {
            text-align: center;
            margin-bottom: 20px;
            color: #45a049;
            /* 深绿色字体 */
        }

        .form-group {
            margin-bottom: 15px;
            text-align: left;
            /* Adjusted text alignment */
        }

        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            /* Added font-weight */
            color: #45a049;
            /* 深绿色字体 */
        }

        .form-group input[type="text"],
        .form-group input[type="password"] {
            width: calc(100% - 10px);
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
            font-size: 16px;
        }

        button {
            display: block;
            width: 100%;
            padding: 12px;
            background-color: #4CAF50;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s ease;
            margin-top: 10px;
            /* Adjusted margin */
        }

        button:hover {
            background-color: #45a049;
        }

        .register-link,
        .password-link {
            text-decoration: none;
            color: #4CAF50;
            /* Green color, matches your button hover color */
            display: inline-block;
            padding: 5px 10px;
            border: 1px solid #4CAF50;
            /* Matching border color */
            border-radius: 4px;
            transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
            margin-top: 10px;
            /* Adjust spacing */
        }

        .register-link:hover,
        .password-link:hover {
            background-color: #4CAF50;
            color: #fff;
        }

        .divider {
            margin: 0 8px;
            /* Adjust spacing between links */
            border-right: 1px solid #ccc;
            height: 14px;
            /* Adjust height to match text height */
            display: inline-block;
            vertical-align: middle;
        }

        footer {
            background-color: #333;
            color: #fff;
            text-align: center;
            padding: 10px 0;
            position: fixed;
            bottom: 0;
            width: 100%;
        }
    </style>
</head>

<body>
    <header>

    </header>
    <main>
        <div class="login-container">
            <h1>登录宠物管理系统</h1>
            <form id="loginForm" method="POST" onsubmit="return loginUser()">
                <div class="form-group">
                    <label for="username">用户名:</label>
                    <input type="text" id="username" name="username" required>
                </div>
                <div class="form-group">
                    <label for="password">密码:</label>
                    <input type="password" id="password" name="password" required>
                </div>
                <button type="submit">登录</button>
            </form>
            <div id="message"></div>
            <a href="/register" class="register-link">点击这里注册</a>
            <span class="divider"></span>
            <a href="/change_password" class="password-link">点击这里修改密码</a>
        </div>
    </main>
    <footer>
        <p>&copy; 2024 宠物管理系统</p>
    </footer>

    <script>
        $(document).ready(function () {
            $('#loginForm').submit(function (event) {
                event.preventDefault();
                var username = $('#username').val();
                var password = $('#password').val();

                $.ajax({
                    type: 'POST',
                    url: '/login',
                    contentType: 'application/json',
                    data: JSON.stringify({ username: username, password: password }),
                    success: function (response) {
                        alert(response.message);
                        if ('登录成功' === response.message) {
                            window.location.href = '/PersonalCenter';
                        }
                    },
                    error: function () {
                        alert('登录失败');
                    }
                });
            });
        });
    </script>
</body>

</html>